import os
import config
import base
import shutil

for p_dir,dirs,files in os.walk(config.annotation_dir):
    if p_dir == config.annotation_dir:
        for name in files:
            if name.find('_') < 0:
                id = os.path.splitext(name)[0]
                xml_path = base.get_annotation_path(id)
                img_path = base.get_img_path(id)

                xml_content = base.read_file_content(xml_path)

                for cls in config.annotation_classes:
                    if xml_content.find(cls) >= 0:
                        new_id = cls.replace(" ","_") + "_" + id
                        new_xml_path = base.get_annotation_path(new_id)
                        new_img_path = base.get_img_path(new_id)

                        print(new_id)
                        shutil.copy(img_path,new_img_path)
                        shutil.copy(xml_path,new_xml_path)
